/**
 * 
 */
package evolution.tutors;

import evolution.mlp.MLP;

/**
 * @author camille
 * 
 */
public class RobotTutor implements Tutor {

	private static final int STEPS = 10000;

	private static RobotTutor singleton;

	private EvolutiveEnvironment environment;

	private RobotTutor() {
		environment = new EvolutiveEnvironment("resources/map1.png");
	}

	public static RobotTutor getInstance() {
		if (singleton == null) {
			singleton = new RobotTutor();
		}

		return singleton;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see evolution.tutors.Tutor#accept(evolution.mlp.MLP)
	 */
	@Override
	public boolean accept(MLP mlp) {
		if ((mlp.getInputLayer().size() == EvolutiveEnvironment.getNeededInputsNumber()) && (mlp.getOutputLayer().size() == EvolutiveEnvironment.getNeededOuputsNumber())) {
			return true;
		} else {
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see evolution.tutors.Tutor#fitness(evolution.mlp.MLP)
	 */
	@Override
	public double fitness(MLP mlp) {

		environment.setMLP(mlp);
		environment.live(STEPS);

		return 1.0d / (environment.getRobot().getFitness());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see evolution.tutors.Tutor#getName()
	 */
	@Override
	public String getName() {
		return "RobotTutor";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see evolution.tutors.Tutor#results(evolution.mlp.MLP)
	 */
	@Override
	public String results(MLP mlp) {
		environment.seeResults(mlp);
		return "Watch results on simbad window";
	}

}
